<?php

namespace app\mall\ui\form;

use app\mall\enum\StatusEnum;
use app\mall\model\MallCate;
use app\mall\model\MallFreightTemplate;

/**
 * 公共商品表单
 */
class MallGoodsForm
{

    public function cate_ids()
    {
        return [
            'type' => 'cascader',
            'title' => '分类',
            'col' => ['span' => 12],
            'field' => 'cate_ids',
            'options' => [MallCate::class, 'getTree'],
            'props' => [
                'show-all-levels' => false,
                'filterable' => true,
                'expandTrigger' => 'hover',
            ],
            'validate' => [
                ['required' => true, 'message' => '不能为空']
            ]
        ];
    }

    public function image()
    {
        return [
            'type' => 'uploadImage',
            'action' => config('thinkAdmin.upload_url'),
            'title' => '封面图片',
            'col' => ['span' => 12],
            'field' => 'image',
            'validate' =>
                [
                    [
                        'required' => true,
                        'message' => '不能为空',
                    ],
                ],
        ];
    }

    public function title()
    {
        return [
            'type' => 'input',
            'title' => '商品名称',
            'col' => ['span' => 12],
            'field' => 'title',
            'validate' =>
                [
                    [
                        'required' => true,
                        'message' => '不能为空',
                    ],
                ],
        ];
    }

    public function ads_title()
    {
        return [
            'type' => 'input',
            'title' => '广告标题',
            'col' => ['span' => 12],
            'field' => 'ads_title',
            'validate' =>
                [
                    [
                        'required' => true,
                        'message' => '不能为空',
                    ],
                ],
        ];
    }


    public function price()
    {
        return [
            'type' => 'number',
            'title' => '价格',
            'col' => ['span' => 12],
            'field' => 'price',
            'props' => [
                'precision' => 2,
            ],
            'validate' =>
                [
                    [
                        'required' => true,
                        'message' => '不能为空',
                    ],
                ],
        ];
    }

    public function price_origin()
    {
        return [
            'type' => 'number',
            'title' => '原价',
            'col' => ['span' => 12],
            'field' => 'price_origin',
            'props' => [
                'precision' => 2,
            ],
            'validate' =>
                [
                    [
                        'required' => true,
                        'message' => '不能为空',
                    ],
                ],
        ];
    }

    /*public function sku()
    {
        return [
            'type' => 'sku',
            'title' => 'SKU',
            'field' => 'sku',
            'props' => [
                'defaultProductNo' => '9999',
                'specs' => [
                    ['name' =>'规格1', 'value' => '红色 黄色'],
                    ['name' =>'规格2', 'value' => '大 小']
                ]
            ]
        ];
    }*/

    /*public function stock_type()
    {
        return [
            'type' => 'radio',
            'col' => ['span' => 12],
            'options' => StockTypeEnum::toZhArrayForSelect(),
            'title' => '库存模式',
            'field' => 'stock_type',
            'value' => StockTypeEnum::getKeyAll(),
        ];
    }*/

    /*public function freight_type()
    {
        return [
            'type' => 'radio',
            'title' => '发货方式',
            'col' => ['span' => 12],
            'options' => FreightEnum::toZhArrayForSelect(),
            'field' => 'freight_type',
            'value' => FreightEnum::getKeyFree(),
        ];
    }*/

    public function freight_id()
    {
        return [
            'type' => 'select',
            'title' => '运费模板',
            'field' => 'freight_id',
            'options' => MallFreightTemplate::buildFreightOptions(),
            /*'validate' => [
                ['required' => true, 'message' => '不能为空']
            ]*/
        ];
    }

    public function inx()
    {
        return [
            'type' => 'number',
            'title' => '排序',
            'col' => ['span' => 12],
            'field' => 'inx',
            'value' => 100,
        ];
    }

    public function status()
    {
        return [
            'type' => 'radio',
            'title' => '状态',
            'col' => ['span' => 12],
            'field' => 'status',
            'options' => StatusEnum::toZhArrayForSelect(),
            'value' => StatusEnum::VALID,
        ];
    }

    public function content()
    {
        return [
            'type' => 'editor',
            'title' => '商品介绍',
            'field' => "detail.content",
            'action' => config('thinkAdmin.upload_url'),
//            'preview' => true
        ];
    }

}